package com.slg.android.manyanime.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.slg.android.manyanime.R;
import com.slg.android.manyanime.bean.Animation;

import java.util.List;

/**
 * Created by Thinkpad on 2015/3/17.
 */
public class ZhuifaninnerAdapter extends BaseAdapter {

    private Context context;

    private List<Animation> data;

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = null;
        if (convertView != null) {
            view = convertView;
        } else {
            view = inflater.inflate(R.layout.item_inner_zhuifan, parent, false);
        }
        ViewHolder viewHolder = (ViewHolder) view.getTag();
        if (viewHolder == null) {
            viewHolder = new ViewHolder();
            viewHolder.AnimeName = (TextView) view.findViewById(R.id.zhuifan_znime_innner_name);
            viewHolder.lastup = (TextView) view.findViewById(R.id.zhuifan_znime_innner_name);
            view.setTag(viewHolder);
        }
        viewHolder.AnimeName = (TextView) view.findViewById(R.id.zhuifan_znime_innner_name);
        viewHolder.lastup = (TextView) view.findViewById(R.id.zhuifan_znime_innner_name);

        viewHolder.AnimeName.setText(data.get(position).getName());
        viewHolder.lastup.setText(data.get(position).getLastUp());
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.putExtra("id", data.get(position).getId());
                context.startActivity(intent);
            }
        });
        return view;

    }

    public ZhuifaninnerAdapter(Context context, List<Animation> data) {
        this.context = context;
        this.data = data;
    }

    public class ViewHolder {

        private TextView AnimeName;
        private TextView lastup;
    }
}



